<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\OrderTaskFileListService;
use Webman\Stomp\RetryAbleConsumer;

class OrderTaskUpstreamDownloadedCheckTaskStatusConsumer extends BaseConsumer implements RetryAbleConsumer
{

    // 要消费的队列名
    public $queue = 'order_task_upstream_downloaded_check_task_status';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 订单上游任务下载完成 检查任务状态
     * @param $data
     * @throws \Throwable
     */
    public function doConsume($data)
    {
        OrderTaskFileListService::getInstance()->orderTaskUpstreamDownloadedCheckTaskStatus($data['id']);
    }

    /**
     * 重试间隔时间
     * @return int
     */
    public function getTtr()
    {
        return 50;
    }

    /**
     * 允许重试次数
     * @param $attempt
     * @param $error
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 3;
    }
}
